package com.example.concurrent.demo.aqs;

import java.util.Date;
import java.util.concurrent.CompletableFuture;

/**
 * @author susc
 * @title: CompletableFutureTest
 * @projectName concurrent-demo
 * @description: TODO
 * @date 2021/9/2816:41
 */
public class CompletableFutureTest {

    public static void main(String[] args) {
        // java8 CompletableFuture 提供了对多线程友好的方法
        CompletableFuture<String> task1 =  CompletableFuture.supplyAsync(
                ()->{
                    System.out.println(new Date());
                    return "success-1";
                });
        CompletableFuture<String> task2 =  CompletableFuture.supplyAsync(
                ()->{
                    System.out.println(new Date());
                    return "success-2";
                });

        CompletableFuture<Void> headFuture = CompletableFuture.allOf(task1, task2);
        headFuture.join();

        System.out.println("all do finish!");

    }
}
